package com.qf.bank.web.controller;

import com.qf.bank.common.bo.CaptchaBO;
import com.qf.bank.web.service.IToolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * @program: bank
 * @description:工具类
 * @author: 徐毫杰
 * @create: 2019-12-09 15:48
 **/
@RestController
public class ToolsController {
    @Autowired
    private IToolService toolService;
    /**
     * 图片验证码
     */
    @RequestMapping(value = "/tool/img",method = RequestMethod.GET)
    public void captcha(HttpServletResponse response) throws IOException {
        CaptchaBO captchaBO = toolService.captchaService();
        //        保存验证码到缓存
//        发送验证码图片到前端
        response.getOutputStream().write(captchaBO.getImg());
    }
    /**
     * 七牛云
     */
    @RequestMapping(value = "/tool/qiniu",method = RequestMethod.GET)
    public String qiniu(@RequestParam String url){
        return toolService.qiniuService(url);
    }
    /**
     * 二维码
     */
    @RequestMapping(value = "/tool/code",method = RequestMethod.GET)
    public void qrCode(@RequestParam String url,HttpServletResponse response) throws IOException {
        byte[] qrCode = toolService.qrCodeService(url);
        response.getOutputStream().write(qrCode);
    }
    /**
     * 短信验证
     */
    @RequestMapping(value = "/tool/phone",method = RequestMethod.GET)
    public Map<String,Boolean> sms(@RequestParam String phone){
        Map<String, Boolean> map = toolService.smsService(phone);
//        传入电话号码，返回验证码
        return map;
    }
    /**
     * 验证码判断
     */
    @RequestMapping(value = "/tool/verify",method = RequestMethod.GET)
    public Boolean verification(@RequestParam String code){
        Boolean result = toolService.verification(code);
        return result;
    }
}

